﻿<UserControl x:Class="DigiFlare.DigiTweet.UI.SearchResultsPanelControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:DigiFlare.DigiTweet.UI.Converters">
    <UserControl.Resources>
        <converters:SearchDetailsConverter x:Key="SearchResultDetails" />
    </UserControl.Resources>
    <Grid>
        <!-- search results -->
        <ItemsControl x:Name="icSearchResults" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
            <ItemsControl.Template>
                <ControlTemplate>
                    <ScrollViewer Grid.Row="0">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ItemsPresenter Grid.Row="0" />
                            <Button x:Name="btnMoreSearchResults"
                                    Grid.Row="1"
                                    Click="MoreResults_Click"
                                    Content="More Results..."
                                    HorizontalAlignment="Right"
                                    Margin="5" Width="100" Height="25" 
                                    Foreground="#FFFFFFFF" Cursor="Hand"
                                    Style="{DynamicResource GenericButton}">
                                <Button.Visibility>
                                    <Binding RelativeSource="{RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}"
                                             Path="ShowMoreSearchResultsVisibility" />
                                </Button.Visibility>
                            </Button>
                        </Grid>
                    </ScrollViewer>
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border Height="Auto" Margin="5,10,5,0" 
                                                        Style="{DynamicResource ItemBorder}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="50" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Image Grid.Row="0" Grid.Column="0"
                                   Source="{Binding AuthorAvatarUrl}"
                                   MouseDown="imgAvatar_MouseDown"
                                   Width="50" Height="50" Margin="5" Cursor="Hand" />
                            <TextBlock Grid.Row="0" Grid.Column="1"
                                       Text="{Binding Path=Title}" 
                                       Foreground="White"
                                       TextWrapping="Wrap"
                                       Loaded="TextBlock_Loaded" />
                            <TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
                                       FontSize="10"
                                       Foreground="White"
                                       VerticalAlignment="Bottom"
                                       Text="{Binding Converter={StaticResource SearchResultDetails}}" />
                        </Grid>
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</UserControl>
